﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using GsnHelper;
using ZhongheCms.Models;

namespace ZhongheCms.Controllers
{
    public class SunHelpController : Controller
    {
        //
        // GET: /SunHelp/

        public ActionResult Index(int id = 0,int pageIndex=1, string m = "", string f = "", string p = "", string fid = "", string sdate = "", string edate = "", string keywords = "")
        {
            ViewBag.m = m;
            ViewBag.f = f;
            ViewBag.p = p;
            ViewBag.fid = fid;
            ViewBag.keywords = keywords;
            ViewBag.sdate = sdate;
            ViewBag.edate = edate;
            ViewBag.pageIndex = pageIndex;
            if (GswTblUser.CurrentUser == null)
                return RedirectToAction("Login", "Account");
            GswTblUser.CurrentUser.ModuleName = m;
            GswTblUser.CurrentUser.FuncName = f;

            var qry = GswViewMemberHelper.GetHelpers(sdate, edate, keywords, GswTblUser.CurrentUser.CustomerId,pageIndex);
            return View(qry);
        }
        [HttpPost]
        public ActionResult DataSave(FormCollection c, int id = 0, int pageIndex = 1, string m = "", string f = "", string p = "", string fid = "", string sdate = "", string edate = "", string keywords = "")
        {
            ViewBag.m = m;
            ViewBag.f = f;
            ViewBag.p = p;
            ViewBag.fid = fid;
            ViewBag.keywords = keywords;
            ViewBag.sdate = sdate;
            ViewBag.edate = edate;
            ViewBag.pageIndex = pageIndex;
            var qry = GswViewMemberHelper.GetHelpers(sdate, edate, keywords, GswTblUser.CurrentUser.CustomerId, pageIndex);
            foreach (var q in qry.Items.Where(q => !string.IsNullOrEmpty(c["chk" + q.Id])))
                GswTblMemberHelp.Update("set AuditFlag=1 where id=" + q.Id);
            var qry1 = GswViewMemberHelper.GetHelpers(sdate, edate, keywords, GswTblUser.CurrentUser.CustomerId, pageIndex);
            return View("Index",qry1);
        }
        public ActionResult Delete(int id,int pageIndex=1,string m = "", string f = "", string p = "", string fid = "", string sdate = "", string edate = "", string keywords = "")
        {
            ViewBag.m = m;
            ViewBag.f = f;
            ViewBag.p = p;
            ViewBag.fid = fid;
            ViewBag.keywords = keywords;
            ViewBag.sdate = sdate;
            ViewBag.edate = edate;
            ViewBag.pageIndex = pageIndex;
            if (GswTblUser.CurrentUser == null)
                return RedirectToAction("Login", "Account");
            GswTblUser.CurrentUser.ModuleName = m;
            GswTblUser.CurrentUser.FuncName = f;
            GswTblMemberHelp.Delete(id);
            var qry = GswViewMemberHelper.GetHelpers(sdate, edate, keywords, GswTblUser.CurrentUser.CustomerId,pageIndex);
            return View("Index",qry);
        }
    }

    
}
